﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;

namespace EWDTAssignment
    {

    public partial class ManageProduct : System.Web.UI.Page
        {


        protected void Page_Load(object sender, EventArgs e)
            {



            if (!IsPostBack)
                {
                TabContainer1.ActiveTabIndex = 0;
                }



            }

        protected void gvProductList_SelectedIndexChanged(object sender, EventArgs e)
            {
            Label lblpID = (Label)gvProductList.SelectedRow.FindControl("lblProductID");
            if (lblpID != null)
                {
                Session["adminP_ID"] = int.Parse(lblpID.Text);
                TabContainer1.ActiveTabIndex = 1;


                }
            }

        protected void btnView_Click(object sender, EventArgs e)
            {
            }

        protected void gvProductList_Sorted(object sender, EventArgs e)
            {

            }

        protected void gvProductList_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
            {

            }

        protected void gvProductList_RowCommand(object sender, GridViewCommandEventArgs e)
            {

            }

        protected void LinkButton1_Click(object sender, EventArgs e)
            {


            }

        protected void txtbxID_TextChanged(object sender, EventArgs e)
            {

            searchProduct();
            }

        protected void gvProductList_DataBound(object sender, EventArgs e)
            {

            }

        protected void gvProductList_PreRender(object sender, EventArgs e)
            {

            if (IsPostBack)
                {
                TextBox txtbxID = (TextBox)gvProductList.HeaderRow.FindControl("txtbxID");
                DropDownList ddlType = (DropDownList)gvProductList.HeaderRow.FindControl("ddlSearchCat");
                TextBox txtbxPname = (TextBox)gvProductList.HeaderRow.FindControl("txtbxpName");

                if (lblsearchResult.Visible == true)
                    {
                    txtbxID.Text = Session["adminP_ID"].ToString();
                    ddlType.SelectedValue = Session["sCat"].ToString();
                    txtbxPname.Text = Session["sPName"].ToString();
                    }
                }
            }

        protected void ddlsearchCat_TextChanged(object sender, EventArgs e)
            {
            searchProduct();
            }

        protected void txtbxPname_TextChanged(object sender, EventArgs e)
            {
            searchProduct();
            }

        protected void btnDisplay_Click(object sender, EventArgs e)
            {
           
            }

        protected void dvPerProduct_ItemCreated(object sender, EventArgs e)
            {

            }

        protected void dvPerProduct_DataBound(object sender, EventArgs e)
            {
            if (IsPostBack)
                {
                if (TabContainer1.ActiveTabIndex == 1)
                    {
                    Label ss = (Label)dvPerProduct.Rows[0].FindControl("lblspec");
                    Label ff = (Label)dvPerProduct.Rows[0].FindControl("lblflag");
                    ListBox listspec = (ListBox)dvPerProduct.Rows[0].FindControl("ListBox1");
                    int specRowcount = 0;
                    List<string> sList = App_Code.BusinessLogic.FormatSpecForProduct(ss.Text);
                    foreach (string txt in sList)
                        {
                        listspec.Items.Add(txt);
                        specRowcount++;
                        }
                    listspec.Rows = specRowcount + 1;
                    //     Literal ltr = (Literal)dvPerProduct.Rows[0].FindControl("ltrflag");
                    //    ltr.Text = ff.Text;
                    ListBox listflag = (ListBox)dvPerProduct.Rows[0].FindControl("listbxFlag");
                    List<string> fList = App_Code.BusinessLogic.FormatFlagForProduct(ff.Text);
                    int flagRowcount = 0;
                    foreach (string txt in fList)
                        {
                        listflag.Items.Add(txt);
                        flagRowcount++;

                        }
                    listflag.Rows = flagRowcount + 1;


                    }


                }
            }


        protected void gvProductList_RowDataBound(object sender, GridViewRowEventArgs e)
            {


            }

        protected void gvProductList_RowCreated(object sender, GridViewRowEventArgs e)
            {

            }


        protected void searchProduct()
            {
            try
                {
                TextBox txtbxID = (TextBox)gvProductList.HeaderRow.FindControl("txtbxID");
                DropDownList ddlType = (DropDownList)gvProductList.HeaderRow.FindControl("ddlSearchCat");
                TextBox txtbxPname = (TextBox)gvProductList.HeaderRow.FindControl("txtbxpName");
                int pID = 0;
                if (txtbxID.Text != "" && txtbxID.Text != " ")
                    {
                    pID = Convert.ToInt32(txtbxID.Text);
                    }
                string type = ddlType.SelectedValue.ToString();
                string pName = txtbxPname.Text;


                Session["sCat"] = type;
                Session["sPName"] = pName;
                Session["adminP_ID"] = txtbxID.Text;




                DataTable dt = App_Code.BusinessLogic.pmsSearchLogic(pID, pName, type);
                if (pID == 0)
                    {
                    Session["sPID"] = " ";
                    }



                gvProductList.DataSourceID = null;
                gvProductList.DataSource = dt;
                gvProductList.DataBind();
                gvProductList.AllowPaging = true;
                //     gvProductList.EnableSortingAndPagingCallbacks = true;

                int count = gvProductList.Rows.Count;

                string textresult = ("Search Result : " + count + " Item(s) Found.");
                lblsearchResult.Visible = true;
                lblsearchResult.Text = textresult;
                }
            catch (Exception e)
                {
                throw e;
                }
            }

        protected void gvProductList_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {
            if (gvProductList.DataSourceID == "")
                {
                gvProductList.PageIndex = e.NewPageIndex;
                gvProductList.DataBind();
                }
            }

       

        #region Logic for creating new product

        protected void DisplayFieldForItem(string productCat)
            {
            string[] pCat = { "cpu", "motherboard", "gfx", "ram", "soundcard", "psu", "casing", "hdd", "monitor", "accessory" };
            foreach (string p in pCat)
                {
                if (productCat.ToLower() == p.ToLower())
                    {
                    EnableFieldForItemFlag_Spec(productCat.ToLower());
                    }
                }
            }
        protected void EnableAllSpecNFlagField()
            {
            //spec
            lblspec1.Visible = true;


            lblspec2.Visible = true;
            lblspec3.Visible = true;
            lblspec4.Visible = true;
            lblspec5.Visible = true;
            lblspec6.Visible = true;
            lblspec7.Visible = true; ;




            txtbxspec1.Visible = true;
            txtbxspec2.Visible = true;
            txtbxspec3.Visible = true;
            txtbxspec4.Visible = true;
            txtbxspec5.Visible = true;
            txtbxspec6.Visible = true;
            txtbxspec7.Visible = true;



            //flag


            lblflag1.Visible = true;

            lblflag2.Visible = true;
            lblflag3.Visible = true;
            lblflag4.Visible = true;
            lblflag5.Visible = true;
            lblflag6.Visible = true;
            lblflag7.Visible = true;
            lblflag8.Visible = true;
            lblflag9.Visible = true;


            //textbox flag to disable
            txtbxflag1a.Visible = true;
            txtbxflag1b.Visible = true;
            txtbxflag2a.Visible = true;
            txtbxflag2b.Visible = true; txtbxflag3a.Visible = true;
            txtbxflag3b.Visible = true; txtbxflag4a.Visible = true;
            txtbxflag4b.Visible = true; txtbxflag5a.Visible = true;
            txtbxflag5b.Visible = true; txtbxflag6a.Visible = true;
            txtbxflag6b.Visible = true; txtbxflag7a.Visible = true;
            txtbxflag7b.Visible = true;
            txtbxflag8.Visible = true;
            txtbxflag9a.Visible = true;
            txtbxflag9b.Visible = true;
            }

        protected void EnableFieldForItemFlag_Spec(string productCat)
            {


            switch (productCat.ToLower())
                {
                case "cpu":

                    //label spec
                    lblspec1.Text = "Frequency:";
                    lblspec2.Text = "Cores:";
                    lblspec3.Text = "L2 cache";
                    lblspec4.Text = "L3 cache";
                    lblspec5.Text = "Multiplier";
                    lblspec6.Text = "Uncore speed";
                    lblspec7.Text = "Voltage (Low):";
                    lblspec8.Text = "Voltage (High):";

                    //label spec to disable
                    //none
                    //txtbox spec to disable
                    //none

                    //textbox spec to disable
                    //none
                    //label flag
                    lblflag1.Text = "Socket";
                    //label flag to disable

                    lblflag2.Visible = false;
                    lblflag3.Visible = false;
                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;
                    lblflag9.Visible = false;

                    //textbox flag to disable

                    txtbxflag1b.Visible = false;
                    txtbxflag2a.Visible = false;
                    txtbxflag2b.Visible = false; txtbxflag3a.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;

                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;
                    break;
                case "motherboard":
                    //label spec
                    lblspec1.Text = "CPU Processor:";
                    lblspec2.Text = "RAM speeds supported:";

                    lblspec3.Text = "Ethernet";
                    lblspec4.Text = "Onboard audio";
                    lblspec5.Text = "External interface";
                    lblspec6.Text = "Additional info";

                    //label spec to disable
                    lblspec7.Visible = false;
                    lblspec8.Visible = false;
                    //txtbox spec to disable
                    txtbxspec7.Visible = false;
                    txtbxspec8.Visible = false;

                    //textbox spec to disable
                    //none
                    //label flag
                    lblflag1.Text = "Expansion 1";
                    lblflag2.Text = "Expansion 2";
                    lblflag3.Text = "Expansion 3";
                    lblflag4.Text = "Expansion 4";
                    lblflag5.Text = "Expansion 5";
                    lblflag6.Text = "Socket:";
                    lblflag7.Text = "Form Factor:";
                    lblflag8.Text = "Ram Type:";
                    lblflag9.Text = "Harddisk type:";




                    break;
                case "gfx":
                    //label spec
                    lblspec1.Text = "GRAM:";
                    lblspec2.Text = "Memory:";
                    lblspec3.Text = "Direct X:";
                    lblspec4.Text = "CPU Clock:";
                    lblspec5.Text = "Memory Clock:";
                    lblspec6.Text = "Warranty:";


                    //label spec to disable
                    lblspec7.Visible = false;
                    lblspec8.Visible = false;
                    //txtbox spec to disable
                    txtbxspec7.Visible = false;
                    txtbxspec8.Visible = false;

                    //textbox spec to disable
                    //none
                    //label flag



                    lblflag1.Text = "Expansion Slot:";

                    lblflag2.Text = "Type of power pin:";


                    lblflag3.Text = "Number of power pins:";



                    //label flag to disable

                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;
                    lblflag9.Visible = false;

                    //textbox flag to disable



                    txtbxflag2b.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;
                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;

                    break;
                case "ram":
                    //label spec
                    lblspec1.Text = "Frequency:";
                    lblspec2.Text = "DRAM Density:";
                    lblspec3.Text = "DRAM N:";
                    lblspec4.Text = "Clock speed:";
                    lblspec5.Text = "Voltage:";
                    lblspec6.Text = "Additional info";
                    lblspec7.Visible = false;
                    lblspec8.Visible = false;

                    //label spec to disable
                    //none
                    //txtbox spec to disable
                    txtbxspec7.Visible = false;
                    txtbxspec8.Visible = false;
                    //textbox spec to disable
                    //none
                    //label flag
                    lblflag1.Text = "RAM Class";
                    lblflag2.Text = "Memory bar:";
                    lblflag3.Text = "Number of Slot:";
                    //label flag to disable


                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;
                    lblflag9.Visible = false;

                    //textbox flag to disable

                    txtbxflag1b.Visible = false;

                    txtbxflag2b.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;
                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;
                    break;
                case "soundcard":
                    //label spec
                    lblspec1.Text = "Surround";

                    //label spec to disable
                    lblspec2.Visible = false;
                    lblspec3.Visible = false;

                    lblspec4.Visible = false;
                    lblspec5.Visible = false;
                    lblspec6.Visible = false;
                    lblspec7.Visible = false;
                    lblspec8.Visible = false;

                    //txtbox spec to disable
                    txtbxspec2.Visible = false;
                    txtbxspec3.Visible = false;
                    txtbxspec4.Visible = false;
                    txtbxspec5.Visible = false;
                    txtbxspec6.Visible = false;
                    txtbxspec7.Visible = false;
                    txtbxspec8.Visible = false;
                    //label flag
                    lblflag1.Text = "Slot";
                    //label flag to disable

                    lblflag2.Visible = false;
                    lblflag3.Visible = false;
                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;

                    lblflag9.Visible = false;
                    //textbox flag to disable

                    txtbxflag1b.Visible = false;
                    txtbxflag2a.Visible = false;
                    txtbxflag2b.Visible = false; txtbxflag3a.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;

                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;
                    break;
                case "psu":
                    //label spec
                    lblspec1.Text = "ATX Main Power Cable:";


                    //label spec to disable
                    lblspec2.Visible = false;//yes / no
                    lblspec3.Visible = false;//yes / no
                    lblspec4.Visible = false;
                    lblspec5.Visible = false;
                    lblspec6.Visible = false;
                    lblspec7.Visible = false;
                    lblspec8.Visible = false;

                    //txtbox spec to disable
                    txtbxspec2.Visible = false;
                    txtbxspec3.Visible = false;
                    txtbxspec4.Visible = false;
                    txtbxspec5.Visible = false;
                    txtbxspec6.Visible = false;
                    txtbxspec7.Visible = false;
                    txtbxspec8.Visible = false;
                    //textbox spec to disable
                    //none
                    //label flag
                    lblflag1.Text = "Capacity";
                    //label flag to disable

                    lblflag2.Visible = false;
                    lblflag3.Visible = false;
                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;
                    lblflag9.Visible = false;


                    //textbox flag to disable

                    txtbxflag1b.Visible = false;
                    txtbxflag2a.Visible = false;
                    txtbxflag2b.Visible = false; txtbxflag3a.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;

                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;
                    break;
                case "casing":
                    //label spec
                    DisableFieldForItemNoSpec();

                    //textbox spec to disable
                    //none
                    //label flag
                    lblflag1.Text = "Form Factor";
                    //label flag to disable

                    lblflag2.Visible = false;
                    lblflag3.Visible = false;
                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;
                    lblflag9.Visible = false;


                    //textbox flag to disable

                    txtbxflag1b.Visible = false;
                    txtbxflag2a.Visible = false;
                    txtbxflag2b.Visible = false; txtbxflag3a.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;
                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;
                    break;
                case "hdd":
                    //label spec
                    lblspec1.Text = "Storage:";
                    lblspec2.Text = "Buffer Size(MB)";
                    lblspec3.Text = "Warranty";

                    //label spec to disable
                    lblspec4.Visible = false;
                    lblspec5.Visible = false;
                    lblspec6.Visible = false;
                    lblspec7.Visible = false;
                    lblspec8.Visible = false;

                    //txtbox spec to disable
                    txtbxspec4.Visible = false;
                    txtbxspec5.Visible = false;
                    txtbxspec6.Visible = false;
                    txtbxspec7.Visible = false;
                    txtbxspec8.Visible = false;

                    //label flag
                    lblflag1.Text = "HDD Type:";
                    //label flag to disable

                    lblflag2.Visible = false;
                    lblflag3.Visible = false;
                    lblflag4.Visible = false;
                    lblflag5.Visible = false;
                    lblflag6.Visible = false;
                    lblflag7.Visible = false;
                    lblflag8.Visible = false;
                    lblflag9.Visible = false;


                    //textbox flag to disable


                    txtbxflag2a.Visible = false;
                    txtbxflag2b.Visible = false; txtbxflag3a.Visible = false;
                    txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
                    txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
                    txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
                    txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
                    txtbxflag7b.Visible = false;
                    txtbxflag8.Visible = false;

                    txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;

                    break;
                case "monitor":
                    DisableFieldForItemNoFlag();
                    DisableFieldForItemNoSpec();
                    break;
                case "accessory":

                    DisableFieldForItemNoFlag();
                    DisableFieldForItemNoSpec();
                    break;

                }

            }
        protected void DisableFieldForItemNoSpec()
            {
            lblspec1.Text = "N/A";

            //label spec to disable
            lblspec2.Visible = false;
            lblspec3.Visible = false;
            lblspec4.Visible = false;
            lblspec5.Visible = false;
            lblspec6.Visible = false;
            lblspec7.Visible = false;
            lblspec8.Visible = false;
            
            //txtbox spec to disable
            //none

            //textbox spec to disable
            txtbxspec1.Visible = false;
            txtbxspec2.Visible = false;
            txtbxspec3.Visible = false;
            txtbxspec4.Visible = false;
            txtbxspec5.Visible = false;
            txtbxspec6.Visible = false;
            txtbxspec7.Visible = false;
            txtbxspec8.Visible = false;

            }
        protected void DisableFieldForItemNoFlag()
            {


            //label flag
            lblflag1.Text = "N/A";
            //label flag to disable

            lblflag2.Visible = false;
            lblflag3.Visible = false;
            lblflag4.Visible = false;
            lblflag5.Visible = false;
            lblflag6.Visible = false;
            lblflag7.Visible = false;
            lblflag8.Visible = false;
            lblflag9.Visible = false;   

            //textbox flag to disable
            txtbxflag1a.Visible = false;
            txtbxflag1b.Visible = false;
            txtbxflag2a.Visible = false;
            txtbxflag2b.Visible = false; txtbxflag3a.Visible = false;
            txtbxflag3b.Visible = false; txtbxflag4a.Visible = false;
            txtbxflag4b.Visible = false; txtbxflag5a.Visible = false;
            txtbxflag5b.Visible = false; txtbxflag6a.Visible = false;
            txtbxflag6b.Visible = false; txtbxflag7a.Visible = false;
            txtbxflag7b.Visible = false;
            txtbxflag8.Visible = false;

            txtbxflag9a.Visible = false; txtbxflag9b.Visible = false;
            }

        protected void ClearFieldAfterCreateProduct()
            {
            txtbxDesc.Text = string.Empty;
            txtbxPName.Text = string.Empty;
            txtbxQty.Text = string.Empty;
            txtbxPrice.Text = string.Empty;

            }

        protected void ddlItemType_SelectedIndexChanged(object sender, EventArgs e)
            {
            EnableAllSpecNFlagField();
            EnableFieldForItemFlag_Spec(ddlItemType.SelectedValue.ToLower());
            }

        protected void Button1_Click(object sender, EventArgs e)
            {


            int success = InsertNewProduct();
            if (success == 1)
                {
                lblmsg.Visible = true;
                lblmsg.Text = "New product created";
                }
            else
                {
                lblmsg.Visible = true;
                lblmsg.Text = "Fail to create product";
                }


            }

        protected int InsertNewProduct()
            {
            App_Code.Product p = new App_Code.Product();
            try
                {

                    if (UploadImage.HasFile)
                    {


                        string savePath = Server.MapPath("//images/");
                        string fileName = UploadImage.FileName;
                        UploadImage.SaveAs(savePath + "//" + fileName);
                        p.ProdImg = savePath + "//" + fileName; //adding image
                    }
                    else p.ProdImg = "~/images/blank.jpg";
              
                    

                p.Description = txtbxDesc.Text;
                p.Category = ddlItemType.SelectedItem.Text;
                p.ProductName = txtbxPName.Text;
                p.Price = decimal.Parse(txtbxPrice.Text);
                p.Quantity = int.Parse(txtbxQty.Text);

                p.Type = int.Parse(ddlproductgrade.SelectedIndex.ToString());


                switch (ddlItemType.SelectedValue.ToLower())
                    {

                    case "cpu": //checked

                        string cpuSpec;
                        //label spec

                        cpuSpec = "freq=" + txtbxspec1.Text + ",";

                        cpuSpec += ("cores=" + txtbxspec2.Text + ",");

                        cpuSpec += ("l2cache=" + txtbxspec3.Text + ",");

                        cpuSpec += ("l3cache=" + txtbxspec4.Text + ",");

                        cpuSpec += ("multi=" + txtbxspec5.Text + ",");

                        cpuSpec += ("uncore=" + txtbxspec6.Text + ",");

                        cpuSpec += ("voltlow=" + txtbxspec7.Text + ",");
                        cpuSpec += ("volthigh=" + txtbxspec8.Text + ",");

                        string cpuflag;

                        cpuflag = ("socket=" + txtbxflag1a.Text + ",");
                        //label flag to disable
                        p.Specification = cpuSpec;
                        p.Flag = cpuflag;

                        break;
                    case "motherboard":
                        //label spec
                        string moboSpec;
                        lblspec1.Text = "CPU Processor:";
                        moboSpec = "cpu=" + txtbxspec1.Text + ",";
                        lblspec2.Text = "RAM speeds supported:";
                        moboSpec += "rss2000=" + txtbxspec2.Text + ",";
                        // moboSpec += "rss1866=" + txtbxfl
                        //moboSpec += "rss1800=" + 
                        //moboSpec += "rss1600=" +
                        lblspec3.Text = "Ethernet";
                        moboSpec += "enet=" + txtbxspec3.Text + ",";
                        lblspec4.Text = "Onboard audio";
                        moboSpec += "audo=" + txtbxspec4.Text + ",";
                        lblspec5.Text = "External interface";
                        moboSpec += "usbport=" + txtbxspec5.Text + ",";
                        lblspec6.Text = "Additional info";
                        moboSpec += "additional=" + txtbxspec6.Text + ",";
                        //jiaxin
                        //label spec to disable
                        lblspec7.Visible = false;
                        lblspec8.Visible = false;
                        //txtbox spec to disable
                        txtbxspec8.Visible = false;

                        //textbox spec to disable
                        //none
                        //label flag
                        string moboFlag;

                        moboFlag = "exp1=" + txtbxflag1a.Text + ",";
                        moboFlag += "exp1N=" + txtbxflag1b.Text + ",";

                        moboFlag += "exp2=" + txtbxflag2a.Text + ",";
                        moboFlag += "exp2N=" + txtbxflag2b.Text + ",";

                        moboFlag += "exp3=" + txtbxflag3a.Text + ",";
                        moboFlag += "exp3N=" + txtbxflag3b.Text + ",";

                        moboFlag += "exp4=" + txtbxflag4a.Text + ";";
                        moboFlag += "exp4N=" + txtbxflag4b.Text + ",";

                        moboFlag += "exp5=" + txtbxflag5a.Text + ",";
                        moboFlag += "exp5N=" + txtbxflag5b.Text + ",";

                        moboFlag += "form=" + txtbxflag6a.Text + ",";

                        moboFlag += "ram=" + txtbxflag7a.Text + ",";
                        moboFlag += "ramN=" + txtbxflag7b.Text + ",";
                        moboFlag += "hdd=" + txtbxflag9a.Text + ",";
                        moboFlag += "hddN=" + txtbxflag9b.Text + ",";


                        p.Specification = moboSpec;
                        p.Flag = moboFlag;

                        break;
                    case "gfx":
                        //label spec

                        string gfxSpec;

                        gfxSpec = "gddrclass=" + txtbxspec1.Text + ",";


                        gfxSpec += "mem=" + txtbxspec2.Text + ",";

                        gfxSpec += "DX=" + txtbxspec3.Text + ",";

                        gfxSpec += "cpuclock=" + txtbxspec4.Text + ",";

                        gfxSpec += "memclock=" + txtbxspec5.Text + ",";

                        gfxSpec += "additional=" + txtbxspec6.Text + ",";



                        string gfxflag = "";

                        gfxflag = "slot=" + txtbxflag1a.Text + ",";
                        gfxflag += "slotN=" + txtbxflag1b.Text + ",";
                        gfxflag += "power=" + txtbxflag2a.Text + ",";
                        gfxflag += "CrossFireX=" + txtbxflag3a.Text + ",";


                        p.Specification = gfxSpec;
                        p.Flag = gfxflag;

                        break;
                    case "ram":

                        string ramSpec;


                        ramSpec = "freq=" + txtbxspec1.Text + ",";

                        ramSpec += "dram=" + txtbxspec2.Text + ",";
                        ramSpec += "dramN=" + txtbxspec3.Text + ",";

                        ramSpec += "timing=" + txtbxspec4.Text + ",";

                        ramSpec += "voltage=" + txtbxspec5.Text + ",";

                        ramSpec += "additional=" + txtbxspec6.Text + ",";

                        string ramFlag;

                        ramFlag = "class=" + txtbxflag1a.Text + ";";

                        ramFlag = "mem=" + txtbxflag2a.Text + ";";

                        ramFlag = "slot=" + txtbxflag2b.Text + ";";


                        p.Specification = ramSpec;
                        p.Flag = ramFlag;

                        break;
                    case "soundcard":

                        string soundSpec;

                        soundSpec = "surround=" + txtbxspec1.Text + ",";

                        string soundFlag;

                        soundFlag = "slot=" + txtbxflag1a.Text + ",";
                        p.Specification = soundSpec;
                        p.Flag = soundFlag;
                        break;
                    case "psu":

                        string psuSpec;

                        psuSpec = "main=" + txtbxspec1.Text + ",";
                        psuSpec += "6pins=6,";
                        psuSpec += "4pins=4,";

                        string psuFlag;

                        psuFlag = "capacity=" + txtbxflag1a.Text + ",";
                        p.Specification = psuSpec;
                        p.Flag = psuFlag;

                        break;
                    case "casing":


                        string casFlag;

                        casFlag = "form=" + txtbxflag1a.Text + ",";
                        p.Specification = "";
                        p.Flag = casFlag;
                        break;
                    case "hdd":

                        string hddSpec;

                        hddSpec = "storage=" + txtbxspec1 + ",";

                        hddSpec += "buffer=" + txtbxspec2 + ",";

                        hddSpec += "warranty=" + txtbxspec3 + ",";

                        string hddflag;
                        hddflag = "type" + txtbxflag1a.Text + ",";

                        p.Specification = hddSpec;
                        p.Flag = hddflag;
                        break;
                    case "monitor":
                        p.Specification = "";
                        p.Flag = "";
                        break;
                    case "accessory":
                        p.Specification = "";
                        p.Flag = "";

                        break;
                    }
                }
            catch (Exception e)
                {

                throw e;
                }
            int success = App_Code.DBManager.InsertProduct(p);
            return success;
            }


        #endregion








        protected void UploadImage_DataBinding(object sender, EventArgs e)
            {

            }

        protected void Image2_DataBinding(object sender, EventArgs e)
            {

            }

        protected void UploadImage_Load(object sender, EventArgs e)
            {

            }

        protected void Button4_Click(object sender, EventArgs e)
            {
            var checkbx = Page.FindControl("CheckBox1") as CheckBox;
            // CheckBox ck = (CheckBox)Page.FindControl("CheckBox1");
            checkbx.Checked = true;
            if (checkbx.Checked == true)
                {

                string uploadpath = "~/images/temppic.jpg";

                Image2.ImageUrl = uploadpath;

                }

            }

        protected void Button5_Click(object sender, EventArgs e)
            {

            if (UploadImage.HasFile)
                {

                string savePath = Server.MapPath("/images");
                string fileName = UploadImage.FileName;
                UploadImage.SaveAs(savePath + "//" + fileName);
                Image2.ImageUrl = savePath + "\\" + fileName;
                }
            else
                {
              
                }
            }

        protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
            {
            if (TabContainer1.ActiveTabIndex == 2)
                {
                btnCreate.Visible = true;
                }
            }

        protected void btnDisplayAll_Click(object sender, EventArgs e)
            {
            lblsearchResult.Visible = false;
            Session["sPID"] = "";
            Session["sCat"] = "";
            Session["sPName"] = "";
            gvProductList.DataSourceID = "dsProduct";
            gvProductList.PageIndex = 0;
            }

        protected void btnDelete_Click(object sender, EventArgs e)
            {
        
        //    int numitem = 0;
            
            foreach (GridViewRow row in gvProductList.Rows)
                {
         
 


            CheckBox   ck = (CheckBox)row.FindControl("cktick");
                Label pID = (Label)row.FindControl("lblProductID");
                
                if (ck.Checked)
                    {
                    //deleting product info from all related tables
                    App_Code.DBManager.RemoveProductFromTablePurchaseOrder(int.Parse(pID.Text));
                     App_Code.DBManager.RemoveProductFromTableComment(int.Parse(pID.Text)); 
                     App_Code.DBManager.RemoveProductFromTableShoppingCart(int.Parse(pID.Text));
                    App_Code.DBManager.RemoveProductFromTablePromotion(int.Parse(pID.Text));
                    App_Code.DBManager.RemoveProductFromTableSetItem(int.Parse(pID.Text));
                    App_Code.DBManager.RemoveProductFromInventory(int.Parse(pID.Text));

                    }
                }

            gvProductList.DataSourceID = "dsProduct";
            gvProductList.DataBind();

            }


        }
    }